package com.tedu.weibo.common.aspect;

import io.github.classgraph.utils.Join;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 该切面用于为所有Controller处理方法添加日志记录
 */
@Component
@Aspect
@Slf4j
public class LogAspect {
    @Before("execution(public com.tedu.weibo.common.result.JsonResult com.tedu.weibo.controller.*.*(..))")
    public void before(JoinPoint joinPoint){
        String methodName = joinPoint.getSignature().getName();
        String className = joinPoint.getTarget().getClass().getName();
        log.info(className + "." + methodName + "()开始执行");
    }
    @AfterReturning("execution(public com.tedu.weibo.common.result.JsonResult com.tedu.weibo.controller.*.*(..))")
    public void afterReturn(JoinPoint joinPoint){
        String methodName = joinPoint.getSignature().getName();
        String className = joinPoint.getTarget().getClass().getName();
        log.info(className + "." + methodName + "()执行完毕");
    }
    @AfterThrowing(
            value = "execution(public com.tedu.weibo.common.result.JsonResult com.tedu.weibo.controller.*.*(..))",
            throwing = "throwable")
    public void afterThrowing(JoinPoint joinPoint,Throwable throwable){
        log.error(throwable.getMessage(),throwable);
    }

}
